package com.fengye.algorithms.leecode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Author fengye
 * @Date 2023/4/28 10:02
 **/
public class Subsets78 {

    public List<List<Integer>> subsets(int[] nums) {
        List<List<Integer>> res = new ArrayList<>();
        List<Integer> subs = new ArrayList<>();
        dfs(0, nums, res, subs);
        return res;
    }

    public void dfs(int cur, int[] nums, List<List<Integer>> res, List<Integer> subs) {
        if(cur == nums.length) {
            res.add(new ArrayList<>(subs));
            return;
        }

        // 考虑当前位置
        subs.add(nums[cur]);
        dfs(cur+1, nums, res, subs);
        // 不考虑当前位置
        subs.remove(subs.size() - 1);
        dfs(cur+1, nums, res, subs);
    }
}
